//
//  SCoAuthModel.swift
//  weibo
//
//  Created by 阿城 on 15/12/7.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit

class SCUserInfoModel: NSObject ,NSCoding{
    
    var access_token: String?
    var expires_in: NSTimeInterval = 0{
        didSet{
            expires_out = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    var expires_out: NSDate?
    var uid: String?
    
    var screen_name :String?        //用户昵称
    var gender :String?             //性别，m：男、f：女、n：未知
    var avatar_large :String?  //头像
    
    override var description: String  {
    
        let keys = ["access_token", "expires_out" ,"expires_in", "uid", "screen_name", "gender", "avatar_large"]
        let showDict = dictionaryWithValuesForKeys(keys)
        return "\(showDict)"
        
    }
    
    convenience init(dict : [String : AnyObject]) {
        self.init()
        self.setValuesForKeysWithDictionary(dict)
    }
    
    override init() {
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        //printLog(key)
    }
    
    required init?(coder aDecoder: NSCoder) {
    
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expires_out = aDecoder.decodeObjectForKey("expires_out") as? NSDate
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        gender = aDecoder.decodeObjectForKey("gender") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(expires_out, forKey: "expires_out")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(gender, forKey: "gender")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        
    }
    
    
    
}




